Skip to content

docs: document LLM event freshness behavior#406

Open
willkill07 wants to merge 2 commits into
NVIDIA:mainfrom
willkill07:docs/relay-445-event-freshness
Open

docs: document LLM event freshness behavior#406
willkill07 wants to merge 2 commits into
NVIDIA:mainfrom
willkill07:docs/relay-445-event-freshness

Conversation

@willkill07

@willkill07 willkill07 commented Jul 11, 2026

Copy link
Copy Markdown
Member

Overview

Document the LLM event-history freshness and compaction behavior implemented by #398. This documentation-only follow-up should merge after #398 so the runtime review can remain focused on implementation and tests.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

  • Explain that fresh agent sessions retain complete sanitized LLM request history and stale sessions retain system instructions, the latest user message, and following assistant or tool messages.
  • Clarify that codec-backed event inputs use the same projection while provider execution remains unchanged.
  • Document freshness ownership for the implicit root, nested agents, and non-agent scopes.
  • Document canonical compaction marks and PreCompact/PostCompact normalization in the CLI guides.
  • Update the ATIF, OpenInference, and observability consumer skills to match the runtime contract.

Validation:

  • just docs
  • uv run pre-commit run --files <nine changed documentation and skill files>
  • git diff --check

Where should the reviewer start?

Start with docs/about-nemo-relay/concepts/events.mdx for the canonical event contract and skills/nemo-relay-export-atif-trajectories/SKILL.md for the retained stale-history shape.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Summary by CodeRabbit

  • Documentation
    • Clarified how sanitized LLM request history is retained across fresh, stale, and compacted agent sessions.
    • Documented request projections used for event annotations and codecs without changing provider execution input.
    • Clarified freshness inheritance for nested and non-agent scopes, including concurrent starts.
    • Updated Claude Code and Codex hook documentation to include PostCompact and canonical compaction marks.
    • Expanded ATIF, OpenInference, and observability guidance for annotated LLM inputs.

Signed-off-by: Will Killian <wkillian@nvidia.com>
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Documentation updates clarify LLM annotation freshness, sanitized request projections, codec behavior, provider execution input, and CLI compaction hook coverage.

Changes

Event Semantics Documentation

Layer / File(s) Summary
LLM annotation freshness and projection
docs/about-nemo-relay/concepts/events.mdx, docs/configure-plugins/observability/atof.mdx, docs/instrument-applications/instrument-llm-call.mdx, skills/nemo-relay-export-atif-trajectories/SKILL.md, skills/nemo-relay-export-openinference/SKILL.md, skills/nemo-relay-setup-observability/SKILL.md
Documentation describes fresh and stale history retention, agent-owned freshness, non-agent inheritance, request codec projections, fallback behavior, and unchanged provider execution input.
CLI compaction hook coverage
docs/nemo-relay-cli/basic-usage.mdx, docs/nemo-relay-cli/claude-code.mdx, docs/nemo-relay-cli/codex.mdx
CLI documentation adds PostCompact coverage and identifies canonical compaction marks emitted by compaction hooks.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses Conventional Commits docs: and clearly summarizes the documentation change.
Description check ✅ Passed The description follows the template sections and includes overview, details, reviewer start, and related issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size:S PR is small Documentation documentation-related labels Jul 11, 2026
@willkill07 willkill07 marked this pull request as ready for review July 11, 2026 00:06
@willkill07 willkill07 requested review from a team and lvojtku as code owners July 11, 2026 00:06
@github-actions

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/about-nemo-relay/concepts/events.mdx`:
- Around line 83-96: Restructure the dense paragraph about LLM start annotations
into a short bulleted list, with one item each for freshness and retention,
nested-agent independence, non-agent scope inheritance, codec projection and
fallback, concurrent-start behavior, and event independence. Preserve all
existing semantics and details while making each concept independently
scannable.

In `@docs/instrument-applications/instrument-llm-call.mdx`:
- Around line 241-245: Update the stale-session annotation description near
“sanitize-request guardrails” to match events.mdx and atof.mdx: state that stale
annotations retain system instructions, the latest user message, and subsequent
assistant/tool messages, rather than only the current user turn. Preserve the
distinction that fresh sessions retain complete history and that the request
codec applies the same projection to emitted event input.

In `@skills/nemo-relay-export-atif-trajectories/SKILL.md`:
- Around line 26-30: Clarify the documentation near the annotation and
projection behavior to distinguish retained annotation history from exported
ATIF content: annotations preserve complete history when available, while the
ATIF adapter’s user-step projection, implemented in the relevant ATIF conversion
logic, includes only the latest User message (or the documented fallback
projection). State that request codecs affect event input projection without
changing provider execution.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: f3ad473f-36f3-4d72-8084-263dc9b2c221

📥 Commits

Reviewing files that changed from the base of the PR and between 9b0c078 and c54cc50.

📒 Files selected for processing (9)
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/configure-plugins/observability/atof.mdx
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • docs/nemo-relay-cli/codex.mdx
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
  • skills/nemo-relay-export-openinference/SKILL.md
  • skills/nemo-relay-setup-observability/SKILL.md
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: CodeRabbit
🧰 Additional context used
📓 Path-based instructions (14)
**/*.{md,rst,html,txt}

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-brand-terminology.md)

**/*.{md,rst,html,txt}: Always spell NVIDIA in all caps. Do not use Nvidia, nvidia, nVidia, nVIDIA, or NV.
Use an NVIDIA before a noun because the name starts with an 'en' sound.
Do not add a registered trademark symbol after NVIDIA when referring to the company.
Use trademark symbols with product names only when the document type or legal guidance requires them.
Verify official capitalization, spacing, and hyphenation for product names.
Precede NVIDIA product names with NVIDIA on first mention when it is natural and accurate.
Do not rewrite product names for grammar or title-case rules.
Preserve third-party product names according to the owner's spelling.
Include the company name and full model qualifier on first use when it helps identify the model.
Preserve the official capitalization and punctuation of model names.
Use shorter family names only after the full name is established.
Spell out a term on first use and put the acronym in parentheses unless the acronym is widely understood by the intended audience.
Use the acronym on later mentions after it has been defined.
For long documents, reintroduce the full term if readers might lose context.
Form plurals of acronyms with s, not an apostrophe, such as GPUs.
In headings, common acronyms can remain abbreviated. Spell out the term in the first or second sentence of the body.
Common terms such as CPU, GPU, PC, API, and UI usually do not need to be spelled out for developer audiences.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • skills/nemo-relay-export-openinference/SKILL.md
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
**/*.{md,rst,html}

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-brand-terminology.md)

Link the first mention of a product name when the destination helps the reader.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • skills/nemo-relay-export-openinference/SKILL.md
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
**/*.{md,rst,txt}

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-guide.md)

Spell NVIDIA in all caps. Do not use Nvidia, nvidia, or NV.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • skills/nemo-relay-export-openinference/SKILL.md
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
**/*.{md,rst}

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-guide.md)

**/*.{md,rst}: Format commands, code elements, expressions, package names, file names, and paths as inline code.
Use descriptive link text. Avoid raw URLs and weak anchors such as "here" or "read more."
Use title case consistently for technical documentation headings.
Introduce code blocks, lists, tables, and images with complete sentences.
Write procedures as imperative steps. Keep steps parallel and split long procedures into smaller tasks.
Prefer active voice, present tense, short sentences, contractions, and plain English.
Use can for possibility and reserve may for permission.
Use after for temporal relationships instead of once.
Prefer refer to over see when the wording points readers to another resource.
Avoid culture-specific idioms, unnecessary Latinisms, jokes, and marketing exaggeration in technical docs.
Spell out months in body text, avoid ordinal dates, and use clear time zones.
Spell out whole numbers from zero through nine unless they are technical values, parameters, versions, or UI values.
Use numerals for 10 or greater and include commas in thousands.
Do not add trademark symbols to learning-oriented docs unless the source, platform, or legal guidance explicitly requires them.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • skills/nemo-relay-export-openinference/SKILL.md
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
**/*.md

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/assets/nvidia-style-technical-docs.md)

**/*.md: Use title case consistently in technical documentation headings
Avoid quotation marks, ampersands, and exclamation marks in headings
Keep product, event, research, and whitepaper names in their official title case
Use title case for table headers
Do not force social-media sentence case into technical docs
Format code elements, commands, parameters, package names, and expressions in monospace
Format directories, file names, and paths in monospace using backticks
Use angle brackets inside monospace for variables inside paths, such as /home/<username>/.login
Format error messages and strings in quotation marks, keeping literal code strings in code formatting when clearer
Format UI buttons, menus, fields, and labels in bold
Use angle brackets between UI labels for menu paths, such as File > Save As
Use italics for new terms on first use, sparingly and only when introducing the term
Use italics for publication titles
Format keyboard shortcuts in plain text, such as Press Ctrl+Alt+Delete
Use owner/repo link text for GitHub repositories, preferring [NVIDIA/NeMo](link) over prose references like 'the GitHub repo'
Introduce every code block with a complete sentence
Do not make a code block complete the grammar of the previous sentence
Do not continue a sentence after a code block
Use syntax highlighting when the format supports it for code blocks
Avoid the word 'snippet' unless the surrounding docs already use it as a term of art
Keep inline method, function, and class references consistent with nearby docs, omitting empty parentheses for prose readability when no call is shown
Use descriptive anchor text that matches the destination title when possible for links
Avoid raw URLs in running text
Avoid generic anchor text such as 'here,' 'this page,' and 'read more'
Include acronyms in link text when a linked term includes an acronym
Do not link long sentences or multiple sentences
Avoid links that pull readers away from a procedure unless the link is a p...

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • skills/nemo-relay-export-openinference/SKILL.md
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
**/SKILL.md

📄 CodeRabbit inference engine (AGENTS.md)

SKILL.md files are skill entrypoints and must start with YAML frontmatter containing at least name and description.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • skills/nemo-relay-export-openinference/SKILL.md
  • skills/nemo-relay-export-atif-trajectories/SKILL.md

⚙️ CodeRabbit configuration file

**/SKILL.md: Do not flag SKILL.md files for missing SPDX headers. Skill entrypoints intentionally start with YAML frontmatter instead.
Verify that every SKILL.md keeps valid YAML frontmatter with at least name and description fields before the Markdown body.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • skills/nemo-relay-export-openinference/SKILL.md
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Update README.md, fern/, package READMEs, and binding-support notes when public behavior, package names, examples, or supported bindings change.

**/*.{md,mdx}: Prefer the documented public API, not internal shortcuts
Keep package names, repo references, and build commands current
Keep release-process and release-notes guidance in repo-maintainer docs such as RELEASING.md, not as user-facing docs pages or CHANGELOG.md
Keep stable user-facing wrappers at scripts/ root in docs and examples; only point at namespaced helper paths when documenting internal maintenance work
When detailed dynamic plugin guides exist, keep Rust native plugin examples, Python worker plugin examples, and grpc-v1 protocol details on separate pages

If links in documentation change, run just docs-linkcheck.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • docs/configure-plugins/observability/atof.mdx
  • skills/nemo-relay-export-openinference/SKILL.md
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/nemo-relay-cli/codex.mdx
**/*.{md,markdown,mdx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add the SPDX license header to all Markdown/MDX documentation files using the HTML comment block form.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • docs/configure-plugins/observability/atof.mdx
  • skills/nemo-relay-export-openinference/SKILL.md
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/nemo-relay-cli/codex.mdx
**/*

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, use maintain-dynamic-plugins and include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, prefer uv run pre-commit run --files <changed files...>.
Before review or handoff, run uv run pre-commit run --all-files.

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • docs/configure-plugins/observability/atof.mdx
  • skills/nemo-relay-export-openinference/SKILL.md
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/nemo-relay-cli/codex.mdx
**

⚙️ CodeRabbit configuration file

**:

AGENTS.md

This file provides guidance to agents, including Claude Code and OpenAI Codex, when working in this repository.

Project Overview

NeMo Relay is a multi-language agent runtime framework for execution scopes, lifecycle events, middleware, plugins, and observability around tool and LLM calls. The core runtime is Rust. Primary supported bindings are Rust, Python, and Node.js. Go and the raw C FFI are experimental and source-first.

The shared runtime model is:

  1. Scope stacks decide where work belongs and which scope-local behavior is visible.
  2. Middleware registries decide what guardrails and intercepts run around managed calls.
  3. Plugins install reusable runtime behavior from configuration.
  4. Events record runtime behavior in ATOF form.
  5. Subscribers and exporters consume events in-process or export them to ATIF, OpenTelemetry, OpenInference, or other backends.

Repository Structure

The repository layout separates the Rust runtime, language bindings,
documentation, integrations, and agent-facing skills.

crates/
  core/       # Rust core runtime crate, published as nemo-relay
  adaptive/   # Adaptive runtime primitives and plugin components
  python/     # PyO3 native extension for the Python package
  ffi/        # Raw C ABI layer used by downstream bindings such as Go
  node/       # NAPI Node.js binding and JavaScript/TypeScript entry points
python/
  nemo_relay/  # Python wrapper package: scopes, tools, LLM, middleware, typed helpers, plugins, adaptive helpers
  tests/      # Python tests
go/
  nemo_relay/  # Experimental Go CGo binding and tests
fern/         # Fern documentation site
scripts/      # Stable wrappers and helper scripts; build/test/docs entry points live in justfile
skills/       # Published Codex/agent skills for NeMo Relay usage patterns

Prerequisites

Insta...

Files:

  • skills/nemo-relay-setup-observability/SKILL.md
  • docs/configure-plugins/observability/atof.mdx
  • skills/nemo-relay-export-openinference/SKILL.md
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • skills/nemo-relay-export-atif-trajectories/SKILL.md
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/nemo-relay-cli/codex.mdx
**/*.mdx

📄 CodeRabbit inference engine (.agents/skills/review-doc-style/SKILL.md)

MDX top-of-file SPDX comments must use {/* ... */} delimiters instead of HTML comment delimiters (Must-Fix)

In MDX files, top-of-file comments must use JSX comment delimiters ({/* to open and */} to close); do not use HTML comments for MDX SPDX headers

Files:

  • docs/configure-plugins/observability/atof.mdx
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/nemo-relay-cli/codex.mdx
{docs,examples}/**/*

📄 CodeRabbit inference engine (.agents/skills/rename-surfaces/SKILL.md)

Update docs and examples.

Files:

  • docs/configure-plugins/observability/atof.mdx
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/nemo-relay-cli/codex.mdx
docs/**/*

📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)

If documentation examples or commands under docs/ change, run the targeted docs checks appropriate to the change.

Files:

  • docs/configure-plugins/observability/atof.mdx
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/nemo-relay-cli/codex.mdx
{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}

⚙️ CodeRabbit configuration file

{docs/**,README.md,CONTRIBUTING.md,RELEASING.md,SECURITY.md}: Review documentation for technical accuracy against the current API, command correctness, and consistency across language bindings.
Flag stale examples, missing SPDX headers where required, and instructions that no longer match CI or pre-commit behavior.

Files:

  • docs/configure-plugins/observability/atof.mdx
  • docs/nemo-relay-cli/basic-usage.mdx
  • docs/nemo-relay-cli/claude-code.mdx
  • docs/instrument-applications/instrument-llm-call.mdx
  • docs/about-nemo-relay/concepts/events.mdx
  • docs/nemo-relay-cli/codex.mdx
🔇 Additional comments (9)
docs/about-nemo-relay/concepts/events.mdx (2)

111-111: LGTM!


93-95: 🎯 Functional Correctness

Clarify the concurrent-start guarantee docs/about-nemo-relay/concepts/events.mdx:93-95 — the implementation path here shows per-call event construction, but not the mechanism that makes “exactly one consumes a fresh state” hold under concurrent starts. Soften the wording or point to the specific ownership/synchronization path.

docs/instrument-applications/instrument-llm-call.mdx (1)

246-248: LGTM!

docs/configure-plugins/observability/atof.mdx (1)

104-108: LGTM!

docs/nemo-relay-cli/claude-code.mdx (1)

125-129: LGTM!

docs/nemo-relay-cli/codex.mdx (1)

184-185: LGTM!

skills/nemo-relay-export-openinference/SKILL.md (1)

32-36: LGTM!

skills/nemo-relay-setup-observability/SKILL.md (1)

41-45: LGTM!

docs/nemo-relay-cli/basic-usage.mdx (1)

309-310: LGTM!

Comment on lines +83 to +96
LLM start annotations retain complete sanitized request history while their
owning agent session is fresh: initially and after a compaction mark. Once the
agent begins a turn, later annotations retain system instructions, the latest
user message, and every following assistant or tool message. Nested agents
track freshness independently. The implicit root is an agent freshness owner.
Non-agent scopes, including function and custom scopes used to model requests,
inherit their nearest agent's freshness instead of starting a new budget. When
a request codec is active, it projects the event's provider-shaped input to the
same history. If that event-only encode fails, Relay retains the complete event
input and annotation and continues the provider call. The request used for
provider execution remains unchanged. Concurrent starts have no guaranteed
emission order, but exactly one consumes a fresh state. Events are independent
observations rather than a replayable history stream.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Dense paragraph mixes six distinct concepts.

This paragraph packs freshness definition, turn-based retention, nested-agent independence, non-agent scope inheritance, codec projection/fallback, and concurrent-start semantics into one block. Splitting into a short bulleted list (one idea per item) would make this easier to scan.

📝 Suggested restructure
-LLM start annotations retain complete sanitized request history while their
-owning agent session is fresh: initially and after a compaction mark. Once the
-agent begins a turn, later annotations retain system instructions, the latest
-user message, and every following assistant or tool message. Nested agents
-track freshness independently. The implicit root is an agent freshness owner.
-Non-agent scopes, including function and custom scopes used to model requests,
-inherit their nearest agent's freshness instead of starting a new budget. When
-a request codec is active, it projects the event's provider-shaped input to the
-same history. If that event-only encode fails, Relay retains the complete event
-input and annotation and continues the provider call. The request used for
-provider execution remains unchanged. Concurrent starts have no guaranteed
-emission order, but exactly one consumes a fresh state. Events are independent
-observations rather than a replayable history stream.
+LLM start annotations retain complete sanitized request history while their
+owning agent session is fresh: initially and after a compaction mark. Once the
+agent begins a turn, later annotations retain system instructions, the latest
+user message, and every following assistant or tool message.
+
+- Nested agents track freshness independently, and the implicit root is an
+  agent freshness owner.
+- Non-agent scopes, including function and custom scopes used to model
+  requests, inherit their nearest agent's freshness instead of starting a new
+  budget.
+- When a request codec is active, it projects the event's provider-shaped
+  input to the same history. If that event-only encode fails, Relay retains
+  the complete event input and annotation and continues the provider call.
+  The request used for provider execution remains unchanged.
+- Concurrent starts have no guaranteed emission order, but exactly one
+  consumes a fresh state. Events are independent observations rather than a
+  replayable history stream.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
LLM start annotations retain complete sanitized request history while their
owning agent session is fresh: initially and after a compaction mark. Once the
agent begins a turn, later annotations retain system instructions, the latest
user message, and every following assistant or tool message. Nested agents
track freshness independently. The implicit root is an agent freshness owner.
Non-agent scopes, including function and custom scopes used to model requests,
inherit their nearest agent's freshness instead of starting a new budget. When
a request codec is active, it projects the event's provider-shaped input to the
same history. If that event-only encode fails, Relay retains the complete event
input and annotation and continues the provider call. The request used for
provider execution remains unchanged. Concurrent starts have no guaranteed
emission order, but exactly one consumes a fresh state. Events are independent
observations rather than a replayable history stream.
LLM start annotations retain complete sanitized request history while their
owning agent session is fresh: initially and after a compaction mark. Once the
agent begins a turn, later annotations retain system instructions, the latest
user message, and every following assistant or tool message.
- Nested agents track freshness independently, and the implicit root is an
agent freshness owner.
- Non-agent scopes, including function and custom scopes used to model
requests, inherit their nearest agent's freshness instead of starting a new
budget.
- When a request codec is active, it projects the event's provider-shaped
input to the same history. If that event-only encode fails, Relay retains
the complete event input and annotation and continues the provider call.
The request used for provider execution remains unchanged.
- Concurrent starts have no guaranteed emission order, but exactly one
consumes a fresh state. Events are independent observations rather than a
replayable history stream.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/about-nemo-relay/concepts/events.mdx` around lines 83 - 96, Restructure
the dense paragraph about LLM start annotations into a short bulleted list, with
one item each for freshness and retention, nested-agent independence, non-agent
scope inheritance, codec projection and fallback, concurrent-start behavior, and
event independence. Preserve all existing semantics and details while making
each concept independently scannable.

Comment on lines +241 to +245
sanitize-request guardrails. Annotations retain complete history while their
agent session is fresh (initially and after compaction); later events contain
the current user turn. With a request codec, the emitted event input uses the
same projection. This event-only projection does not change the request used
for provider execution.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Stale-session retention description is inconsistent with events.mdx and atof.mdx.

This says stale annotations "contain the current user turn," but events.mdx (lines 85-86) and atof.mdx (lines 105-107) both specify that stale annotations retain system instructions, the latest user message, and subsequent assistant/tool messages. As written here, a reader could conclude the system prompt is dropped once a turn begins.

📝 Suggested wording fix
-  sanitize-request guardrails. Annotations retain complete history while their
-  agent session is fresh (initially and after compaction); later events contain
-  the current user turn. With a request codec, the emitted event input uses the
+  sanitize-request guardrails. Annotations retain complete history while their
+  agent session is fresh (initially and after compaction); later events retain
+  system instructions, the latest user message, and subsequent assistant or
+  tool messages. With a request codec, the emitted event input uses the
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sanitize-request guardrails. Annotations retain complete history while their
agent session is fresh (initially and after compaction); later events contain
the current user turn. With a request codec, the emitted event input uses the
same projection. This event-only projection does not change the request used
for provider execution.
sanitize-request guardrails. Annotations retain complete history while their
agent session is fresh (initially and after compaction); later events retain
system instructions, the latest user message, and subsequent assistant or
tool messages. With a request codec, the emitted event input uses the
same projection. This event-only projection does not change the request used
for provider execution.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/instrument-applications/instrument-llm-call.mdx` around lines 241 - 245,
Update the stale-session annotation description near “sanitize-request
guardrails” to match events.mdx and atof.mdx: state that stale annotations
retain system instructions, the latest user message, and subsequent
assistant/tool messages, rather than only the current user turn. Preserve the
distinction that fresh sessions retain complete history and that the request
codec applies the same projection to emitted event input.

Comment on lines +26 to +30
request annotation when possible. Annotations retain complete history while
their agent session is fresh (initially and after compaction); otherwise, the
projection retains system instructions, the latest user message, and following
assistant or tool messages. With a request codec, the event input uses the same
projection; provider execution remains unchanged.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Clarify annotation history versus exported ATIF content.

The ATIF adapter in crates/core/src/observability/atif.rs:1040-1105 currently projects only the latest User message into the ATIF message; it does not emit the complete annotated history. Clarify that full history is retained by the annotation, while the ATIF user-step projection is narrower.

Suggested wording
-  request annotation when possible. Annotations retain complete history while
+  request annotation when possible. The annotation retains complete history while
   their agent session is fresh (initially and after compaction); otherwise, the
-  projection retains system instructions, the latest user message, and following
-  assistant or tool messages. With a request codec, the event input uses the same
-  projection; provider execution remains unchanged.
+  annotation projection retains system instructions, the latest user message, and
+  following assistant or tool messages. The ATIF user-step projection extracts
+  the latest user message. With a request codec, the event input uses the same
+  annotation projection; provider execution remains unchanged.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/nemo-relay-export-atif-trajectories/SKILL.md` around lines 26 - 30,
Clarify the documentation near the annotation and projection behavior to
distinguish retained annotation history from exported ATIF content: annotations
preserve complete history when available, while the ATIF adapter’s user-step
projection, implemented in the relevant ATIF conversion logic, includes only the
latest User message (or the documented fallback projection). State that request
codecs affect event input projection without changing provider execution.

@willkill07 willkill07 added this to the 0.6 milestone Jul 11, 2026
@willkill07 willkill07 self-assigned this Jul 11, 2026
rapids-bot Bot pushed a commit that referenced this pull request Jul 11, 2026
#### Overview

> [!WARNING]
> **BREAKING CHANGE (Behavioral):** LLM start request event inputs and annotations can omit earlier turns after the owning agent's freshness has been consumed. The request used for provider execution remains unchanged.

Implement RELAY-445 with per-agent freshness. A new agent session, and the first LLM start after compaction, retains the complete sanitized request history. Later starts cull the annotation and codec-backed event input to the current user turn.

- [x] I confirm this contribution is my own work, or I have the right to submit it under this project's license.
- [x] I searched existing issues and open pull requests, and this does not duplicate existing work.

#### Details

- Track freshness for the implicit root and nested agent scopes independently, and remove explicit-agent state when its scope closes. Non-agent scopes inherit their nearest agent's freshness instead of creating a separate budget.
- Atomically consume freshness at LLM start. Concurrent starts need not have a stable emission order, but exactly one consumes a fresh state.
- Mark the owning agent fresh on canonical `compaction` events. Repeated marks are idempotent, and both `PreCompact` and `PostCompact` normalize to the shared canonical event name.
- For stale agents, retain system instructions, the latest user message, and every following assistant or tool message. Handle empty, instruction-only, and no-user histories without cloning an annotation when projection is a no-op.
- When a request codec is active, encode the projected annotation into the event-only `LlmRequest` so `event.input` and `category_profile.annotated_request` contain the same bounded history. If that event-only encode fails, emit a diagnostic, preserve the complete event input and annotation, and continue the provider call.
- Leave response payloads, middleware/provider requests, caller-visible values, and existing public API signatures unchanged. This implementation has no history baselines, ordering queues, or response projection.
- Keep ordinary mark events on the scope-stack read-lock path; acquire the write lock only for canonical compaction marks.
- Add real-codec coverage for managed and streaming calls, including fail-open encode errors; projection edge cases and no-op allocation behavior; implicit-root and nested-agent inheritance; concurrent starts; and repeated compaction marks.
- Move documentation and consumer-skill updates to the documentation-only follow-up PR #406.

Validation:

- `cargo fmt --all`
- `just test-rust` — 833 core unit tests plus integration tests passed
- `cargo clippy --workspace --all-targets -- -D warnings`
- `just test-python` — 511 passed
- `just test-node` — 254 passed
- `just test-go`
- `uv run pre-commit run --all-files`

#### Where should the reviewer start?

Start with `crates/core/src/api/runtime/scope_stack.rs` for the root/nested-agent freshness ownership, `crates/core/src/api/llm.rs` for fail-open event-only request projection, and `crates/core/tests/unit/llm_api_tests.rs` for the behavioral contract.

#### Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

- Fixes: RELAY-445

Authors:
  - Will Killian (https://github.com/willkill07)

Approvers:
  - Maryam Najafian (https://github.com/mnajafian-nv)

URL: #398
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation documentation-related size:S PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant